/**
 * SeriesViewTest
 * @Chunning.Xu
 * 2011 Nov 23, 2011 2:38:28 PM
 **/
package
{
	import com.lux.product.controllers.SeriesController;
	import com.lux.product.models.CategoryModel;
	import com.lux.product.models.ProductModel;
	import com.lux.product.models.SeriesModel;
	
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.utils.ByteArray;
	import flash.utils.setTimeout;
	
	[SWF(backgroundColor=0x000000)]
	public class SeriesViewTest extends Sprite
	{
		//START.
		
		public static function convertByteToXML(byteClass:Class):XML
		{
			var bytes:ByteArray = new byteClass;
			var strData:String = bytes.readUTFBytes(bytes.length);
			
			XML.ignoreWhitespace = true;
			var xml:XML = new XML(strData);
			
			return xml;
		}
		
		[Embed(source="xml/products.xml",mimeType="application/octet-stream")]
		private var productsClass:Class;
		
		private var seriesController:SeriesController;
		private var cateModel:CategoryModel;
		
		public function SeriesViewTest()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var prdsXML:XML = convertByteToXML(productsClass);
			cateModel = new CategoryModel;
			cateModel.setXML(prdsXML["category"][0]);
			cateModel.addEventListener(Event.COMPLETE,onDataInit);
		}

		private function onDataInit(evt:Event):void
		{
			seriesController = new SeriesController(cateModel.series[0]);
			
			setTimeout(function():void
			{
				seriesController.setIndex(1);
				setTimeout(function():void
				{
					seriesController.setIndex(0);
					setTimeout(function():void
					{
						seriesController.setIndex(2);
					},2000);
				},2000);
			},2000);
			this.addChild(seriesController.view);
		}
		
		//END
	}
}